package com.leyou.item.web;

import com.leyou.common.dto.SpecGroupDTO;
import com.leyou.common.dto.SpecParamDTO;
import com.leyou.item.service.ParamService;
import com.leyou.item.service.SpectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/spec")
public class SpectController {
   @Autowired
   private SpectService spectService;

   //根据商品分类id,查询规格组的集合
  @GetMapping("/groups/of/category")
 public ResponseEntity<List<SpecGroupDTO>> findGroupByCategoryId(@RequestParam("id") Long id){

      return ResponseEntity.ok(spectService.findGroupByCategoryId(id));
 }
  //根据分类id查询规格组及组内参数
    @GetMapping("/list")
    public ResponseEntity<List<SpecGroupDTO>> findGroupAndSpectByCategoryId(@RequestParam("id") Long id){
      return ResponseEntity.ok(spectService.findGroupAndSpectByCategoryId(id));
    }
    //新增规格组
    @PostMapping("/group")
    public ResponseEntity<Void> addParamGroup(@RequestBody SpecGroupDTO groupDTO){
      spectService.addParamGroup(groupDTO);
      return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
    }
    //修改规格组
   @PutMapping("/group")
    public ResponseEntity<Void> postParamGroup(@RequestBody SpecGroupDTO groupDTO){
      spectService.postParamGroup(groupDTO);
      return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
    }
    //新增规格参数
    @PostMapping("/param")
    public ResponseEntity<Void> addParam(@RequestBody SpecParamDTO specParamDTO){
      spectService.addParam(specParamDTO);
      return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
    }//修改规格参数
    @PutMapping("/param")
    public ResponseEntity<Void> postParam(@RequestBody SpecParamDTO specParamDTO){
        spectService.postParam(specParamDTO);
      return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
    }
    //条件查询规格参数集合
    @GetMapping("/params")
    public ResponseEntity<List<SpecParamDTO>> queryParamList(@RequestParam(value = "categoryId",required = false) Long categoryId,
                                                             @RequestParam(value = "groupId",required = false) Long groupId ,
                                                             @RequestParam(value = "searching",required = false) Boolean searching
                                                             ){
     return ResponseEntity.ok(spectService.queryParamList(categoryId,groupId,searching));
    }

}
